import datetime

from flask import Flask
from flask_bootstrap import Bootstrap
from flask_login import LoginManager
from flask_ckeditor import CKEditor
from flask_sqlalchemy import SQLAlchemy
from flask_wtf import CSRFProtect
from flask_mail import Mail
import read_config

app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = read_config.read_ini("resources/flask-db.ini")
app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['BOOTSTRAP_SERVE_LOCAL'] = True
app.config['SECRET_KEY'] = 'this is a random string'
app.PERMANENT_SESSION_LIFETIME = datetime.timedelta(seconds=1)

# flask_login
login_manager = LoginManager()
login_manager.blueprint_login_views = {
    'admin': 'admin.admin_login',
    'user': 'user.Login_form'
}
login_manager.login_message = '您必须先登录'
login_manager.init_app(app)
# flask_ckeditor
ckeditor = CKEditor(app)
app.config['CKEDITOR_SERVE_LOCAL'] = True
app.config['CKEDITOR_HEIGHT'] = 300
# CSRFProtect
csrf = CSRFProtect(app)
# flask_bootstrap
bootstrap = Bootstrap(app)
# flask_sqlalchemy
db = SQLAlchemy(app)
# flask_mail
app.config['MAIL_SERVER'] = "smtp.qq.com"
app.config['MAIL_PORT'] = "587"
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = "3204691340@qq.com"
app.config['MAIL_PASSWORD'] = "hzirqhagdpjedehj"  # {”大号“：ojsivaatdcnqjeib，”小号“：hzirqhagdpjedehj，manfjkpvrpjhddeg}
app.config['MAIL_DEFAULT_SENDER'] = "3204691340@qq.com"
mail = Mail(app)
